package com.captjack.micro.task.configuration.elasticjob;

import com.dangdang.ddframe.job.reg.zookeeper.ZookeeperConfiguration;
import com.dangdang.ddframe.job.reg.zookeeper.ZookeeperRegistryCenter;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author Capt Jack
 * @date 2018/6/1
 */
@Configuration
@ConditionalOnProperty(prefix = "elastic-job", name = "enable", havingValue = "true")
public class ElasticJobZookeeperConfiguration {

    /**
     * 任务注册中心
     *
     * @param serverList 服务配置
     * @param namespace  命名空间
     * @return 配置中心
     */
    @Bean(name = "elasticJobRegisterCenter", initMethod = "init")
    ZookeeperRegistryCenter zookeeperRegistryCenter(@Value("${elastic-job.serverList}") final String serverList, @Value("${elastic-job.namespace}") final String namespace) {
        return new ZookeeperRegistryCenter(new ZookeeperConfiguration(serverList, namespace));
    }

}
